import Sprite   from '../base/sprite'
import DataBus  from '../databus'
const databus = new DataBus()

export default class Player extends Sprite{
    constructor() {
        super()
        this.initEvent()
    }

    initEvent() {
        wx.onTouchStart(e => {
            this.canvasX = e.touches[0].clientX
            this.canvasY = e.touches[0].clientY

            const gridOccupied = Object.values(databus.grid).filter(g => g.occupied)
            gridOccupied.forEach(g => {
                if(this.isIn(g.x, g.y, databus.gridConfig.unitW, databus.gridConfig.unitH))
                    g.occupied.tapped()
            })
        })
    }

    endEvent() {

    }
}